home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-05-03 | 8.0 KB | 258 lines | [TEXT/CCL2] |
-
- ;modified 11/10/92 - changing to packages
- ;modified 11/25/92 - code cleanup, move flag display to its own file
-
- (in-package "VOICE-TOOLKIT")
- (export '(set-voice-handler close-voice-handler))
-
- ;************************************************************************************
-
- ;data structures used by Voice Handler
-
- (defparameter *voice-system* nil
- "is set to t the first time speech input arrives for processing")
-
- (defparameter *attention* nil
- "boolean for whether Cookie is alerted for voice input")
-
- (defparameter *screen* nil "currently focused voice window")
-
- (defparameter *wordtable* (make-hash-table :test #'equal)
- "Each word keyed to list of items whose labels contain the word")
-
- (defparameter *wordlist* nil
- "list of words heard since *attention* became true")
-
- (defparameter *marked* nil
- "list of the currently marked items")
-
- (defparameter *fixes* nil "list of possible fixes")
-
- (defparameter *mark-method* :ITALIC
- "method used to indicate possible items on screen")
-
- (defparameter *start-word* "LISTEN"
- "word which alerts handler for further input")
-
- (defparameter *fire-word* "GO"
- "word which tells handler to simulate mouse click on indicated item")
-
- (defparameter *cancel-word* "FORGET IT"
- "word which tells handler to cancel input and become unalert")
-
- (defparameter *next-guess* "NEXT"
- "word which tells handler to indicate next guess, if applicable")
-
- (defparameter *guessing* nil
- "boolean to set guessing functionality on or off")
-
- ;*********************************************************************************
-
- ;exported functions
-
- (defun set-voice-handler (&key (alert-on 'keep)
- cancel-on
- (accept-on 'keep)
- next-guess-on
- (guessing-p *guessing*)
- mark-method)
- "Allows user modifications to Voice Handler behavior"
- (if (not (equal alert-on 'keep))
- (if (or (not alert-on) (stringp alert-on))
- (setf *start-word* (if (stringp alert-on)
- (string-upcase alert-on)
- alert-on))
- (error "~a is not a valid alert-on (must be a string)" alert-on)))
- (if cancel-on
- (if (stringp cancel-on)
- (setf *cancel-word* (string-upcase cancel-on))
- (error "~a is not a valid cancel-on (must be a string)" cancel-on)))
- (if (not (equal accept-on 'keep))
- (if (or (not accept-on) (stringp accept-on))
- (if (and *guessing* (not accept-on))
- (error "Must have a word for accept-on while guessing is enabled")
- (setf *fire-word* (if (stringp accept-on)
- (string-upcase accept-on)
- accept-on)))
- (error "~a is not a valid accept-on (must be a string)" accept-on)))
- (if next-guess-on
- (if (stringp next-guess-on)
- (setf *next-guess* (string-upcase next-guess-on))
- (error "~a is not a valid next-guess-on (must be a string)"
- next-guess-on)))
- (if (and guessing-p (not *guessing*))
- (if *fire-word*
- (progn
- (setf *guessing* guessing-p)
- (load-twins))
- (error "A word must first be provided for accept-on so that a guess may be validated")))
- (if (and (not guessing-p) *guessing*)
- (progn
- (setf *guessing* guessing-p)
- (file-twins (report-twins))))
- (if mark-method
- (if (valid mark-method)
- (setf *mark-method* (valid mark-method))
- (error "Mark-method must be ITALIC, BOLD or a color value")))
- (if (and *screen* (not *start-word*) (not *attention*)) (pay-attention)))
-
- (defun close-voice-handler ()
- "shuts down voice handler"
- (hide-flag)
- (if *guessing* (file-twins (report-twins))))
-
- ;*********************************************************************************
-
- ;functions used for interface between Voice Handler and voice objects
-
-
- (defun new-voice-window (vw)
- (cond ((not (eq *screen* vw))
- (remove-voice-window *screen*)
- (setf *screen* vw)
- (identify vw)
- (and *voice-system*
- (show-flag))
- (if (null *start-word*) (pay-attention)))
- (t nil)))
-
-
- (defun remove-voice-window (vw)
- (if (eq *screen* vw)
- (progn (clrhash *wordtable*)
- (reset-voice)
- (setf *screen* nil)
- (hide-flag))))
-
-
- (defun onscreen-p (item)
- (equal (view-container item) *screen*))
-
-
- (defun reset-voice ()
- (if *attention* (drop-attention)))
-
-
- (defun file-voice-item (item)
- "puts new item into hash table"
- (mapcar #'(lambda (word)
- (setf (gethash word *wordtable*)
- (union (find-items (list word)) (list item))))
- (string-to-wordlist (string-upcase (text item)))))
-
-
- (defun file-voice-items (itemlist)
- (mapcar #'file-voice-item itemlist))
-
-
- (defun remove-voice-item (item)
- "removes item from hash table and item list"
- (reset-voice)
- (mapcar #'(lambda (word)
- (setf (gethash (string-upcase word) *wordtable*)
- (set-diff (gethash (string-upcase word) *wordtable*)
- (list item))))
- (string-to-wordlist (text item))))
-
-
- (defun remove-voice-items (itemlist)
- (mapcar #'remove-voice-item itemlist))
-
-
- ;*************************************************************************************
-
- ;Voice Navigator handler code
-
- (defun hear (word)
- "this is the function directly called by the Voice Navigator via appleevent"
- (if *attention*
- (cond ((equal word *fire-word*)
- (if (successful)
- (drop-attention)))
- ((equal word *cancel-word*)
- (drop-attention))
- ((and *fixes* (equal word *next-guess*))
- (if (null (rest *fixes*))
- (progn
- (setf *fixes* nil)
- (mark-items nil)
- (frown))
- (progn
- (setf *fixes* (rest *fixes*))
- (mark-items (list (fix-item))))))
- (t (setf *wordlist* (cons word *wordlist*))
- (setf *fixes* nil)
- (mark-items (find-items *wordlist*))
- (cond ((and *marked* (null (rest *marked*)))
- (if (and *fire-word* (careful (first *marked*)))
- (smile)
- (hear *fire-word*)))
- (*marked* (question))
- ((and (null *marked*) *guessing* (guess-fixes))
- (mark-items (list (fix-item)))
- (question-guess))
- (t (frown)))))
- (if (equal word *start-word*) (pay-attention)))
- (values))
-
-
- (defun pay-attention ()
- (setf *attention* t)
- (and *voice-system* (question)))
-
-
- (defun drop-attention ()
- (if *start-word*
- (progn
- (setf *attention* nil)
- (and *voice-system* (blank-flag)))
- (and *voice-system* (question)))
- (setf *wordlist* nil)
- (setf *fixes* nil)
- (mark-items nil))
-
-
- (defun successful ()
- "if possible items narrowed to one, select that one"
- (if (and *marked* (null (rest *marked*)))
- (progn
- (if *fixes* (record-fix))
- (activate (first *marked*))
- t)))
-
-
- (defun activate (item)
- "necessary to be sure that the AppleEvent handler returns so that
- further event processing can take place"
- (setf *eventhook*
- (cons #'(lambda ()
- (setf *eventhook*
- (rest *eventhook*))
- (select item)
- nil)
- (if (listp *eventhook*) *eventhook* (list *eventhook*)))))
-
-
- (defun find-items (words)
- (if (null (rest words))
- (gethash (first words) *wordtable*)
- (if (and *marked* (null *fixes*))
- (intersection *marked*
- (gethash (first words) *wordtable*)))))
-
-
- (defun mark-items (items)
- (mapcar #'mark (set-diff items *marked*))
- (mapcar #'unmark (set-diff *marked* items))
- (setf *marked* items))
-
-
- (defmethod voice-handler ((a application) theAppleEvent reply handlerRefcon)
- (if *screen* (voice-handler *screen* theAppleEvent reply handlerRefcon)))
-
-
- (install-appleevent-handler :|aevt| :|hear| #'voice-handler)
-
-
- ;**********************************************************************************
-